package flc.ast.adapter;


import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.TimeZone;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.bean.StkResBean;

public class HomeTextAdapter extends StkProviderMultiAdapter<StkResBean> {


    public HomeTextAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new HomeTextProvider());
    }

    private class HomeTextProvider extends BaseItemProvider<StkResBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_home_text;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, StkResBean bean) {
            Glide.with(getContext()).load(bean.getThumbUrl())
                    .into((ImageView) baseViewHolder.getView(R.id.ivHomeTextItemImg));
            baseViewHolder.setText(R.id.tvHomeTextItemName, bean.getDesc());
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
            format.setTimeZone(TimeZone.getTimeZone("UTC"));
            try {
                Date date = format.parse(bean.getCreateAt());
                String time = new SimpleDateFormat("yyyy年MM月dd日").format(date);
                baseViewHolder.setText(R.id.tvHomeTextItemDate, time);
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }

            Random random = new Random();
            baseViewHolder.setText(R.id.tvHomeTextItemNum, getContext().getString(R.string.look_num, random.nextInt(1000)));

        }
    }

}
